package com.xawl.service.impl;

import com.xawl.dao.UserMapper;
import com.xawl.pojo.*;
import com.xawl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    public Integer getTotal() {
        return userMapper.getTotal();
    }

    @Override
    public User findUserById(int u_id) {
        return userMapper.findUserById(u_id);
    }

    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public int registerUser(User user) {
        return userMapper.registerUser(user);
    }

    public int deleteUser(int u_id) {
        return userMapper.deleteUser(u_id);
    }

    @Override
    public int deleteUsers(Long[] ids) {
        return userMapper.deleteUsers(ids);
    }

    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    public List<User> queryAll() {
        return userMapper.queryAllUser();
    }

    public List<CourseLearning> queryAllCourse() {
        return userMapper.queryAllCourse();
    }

    public List<PopularNav> queryAllNav() {
        return userMapper.queryAllNav();
    }

    public User queryUserByName(String username) {
        return userMapper.queryUserByName(username);
    }

    public User checkLogin(String username, String password) {
        User user = userMapper.queryUserByName(username);
        if (user != null && user.getPassword().equals(password)) {
            return user;
        }
        return null;
    }

    public List<User> searchUser(String username) {
        return userMapper.searchUser(username);
    }

}
